<?php

namespace app\common\job;


use app\common\exception\MiException;
use app\common\service\CommonOrderService;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;

/***
 * 商城相关的队列任务
 */
class StoreQueueJob
{

    private static ?self $_instance;

    public static function instance():static
    {
        if (!isset($people->name) || !self::$_instance){
            self::$_instance = new self();
        }
        return self::$_instance;
    }

    // 私有化构造函数
    private function __construct()
    {
    }

    /**
     * 订单超时未支付，自动取消订单（直接关闭）
     * @throws DataNotFoundException
     * @throws ModelNotFoundException
     * @throws DbException
     * @throws MiException
     */
    public function orderCancel($data){
        CommonOrderService::instance()->cancel($data['order_id'], 'cancel');
    }

    // 自动确认收货
    public function orderReceive($data){
        CommonOrderService::instance()->receive($data['order_id']);
    }

    /**
     * 自动关闭订单
     * @throws DataNotFoundException
     * @throws ModelNotFoundException
     * @throws DbException
     * @throws MiException
     */
    public function orderClose($data){
        CommonOrderService::instance()->close($data['order_id'], 'auto');
    }

}
